local units = units
local print = print

function UnitRace(unit)
	local u = units.ResolveUnit(unit)
	if u and u.race then
		local r = units.GetRaceInfo(u.race)
		return r.name, u.race
	end
end

function UnitName(unit)
	local u = units.ResolveUnit(unit)
	if u then
		return u.name
	end
end

function UnitGUID(unit)
	local u = units.ResolveUnit(unit)
	if u then
		return u.guid
	end
end

function UnitClass(unit)
	local u = units.ResolveUnit(unit)
	if u and u.class then
		local c = units.GetClassInfo(u.class)
		return c.name, u.class
	end
end

function GetDefaultLanguage(unit)
	local u = units.ResolveUnit(unit or "player")
	if u then
		return u.lang[1]
	end
end

function UnitIsUnit(unit1, unit2)
	local u1, u2 = units.ResolveUnit(unit1), units.ResolveUnit(unit2)
	return u1 == u2
end

function UnitChannelInfo(unit)
end

function UnitCastingInfo(unit)
end

function UnitXP(unit)
	local u = units.ResolveUnit(unit)
	if u then
		return u.xp
	end
end

function UnitXPMax(unit)
	local u = units.ResolveUnit(unit)
	if u then
		return units.GetXPToLevel(u.level)
	end
end

function UnitHealth(unit)
	local u = units.ResolveUnit(unit)
	return u and u.health or 0
end

function UnitHealthMax(unit)
	-- print("UnitHealthMax", unit)
	local u = units.ResolveUnit(unit)
	return u and u.healthmax or 0
end

function UnitPower(unit, type)
	local u = units.ResolveUnit(unit)
	return u and u.mana or 0
end

function UnitPowerMax(unit, type)
	local u = units.ResolveUnit(unit)
	return u and u.manamax or 0
end

function UnitExists(unit)
	local u = units.ResolveUnit(unit)
	if u then
		return 1
	end
end

function UnitIsPlayer(unit)
	return UnitIsUnit(unit, "player")
end

function UnitIsConnected(unit)
	local u = units.ResolveUnit(unit)
	if u and not u.disconnected then
		return 1
	end
end

function UnitIsDead(unit)
	local u = units.ResolveUnit(unit)
	if u and u.dead then
		return 1
	end
end

function UnitIsGhost(unit)
	local u = units.ResolveUnit(unit)
	if u and u.ghost then
		return 1
	end
end

function UnitIsDeadOrGhost(unit)
	local u = units.ResolveUnit(unit)
	if u and (u.dead or u.ghost) then
		return 1
	end
end

function UnitCanCooperate(unit1, unit2)
	local u1, u2 = units.ResolveUnit(unit1), units.ResolveUnit(unit2)
	if u1 and u2 and u1.faction == u2.faction then
		return 1
	end
end

function UnitCanAttack(unit1, unit2)
	local u1, u2 = units.ResolveUnit(unit1), units.ResolveUnit(unit2)
	if u1 and u2 and u1.faction ~= u2.faction then
		return 1
	end
end

function UnitLevel(unit)
	local u = units.ResolveUnit(unit)
	if u then
		return u.level
	end
end

function UnitFactionGroup(unit)
	local u = units.ResolveUnit(unit)
	if u and u.faction then
		local f = units.GetFactionInfo(u.faction)
		return f.name, u.class
	end
end

function UnitIsPVPFreeForAll(unit)
	local u = units.ResolveUnit(unit)
	if u then
		return u.pvp == "freeforall"
	end
end

function UnitIsPVP(unit)
	local u = units.ResolveUnit(unit)
	if u then
		return u.pvp ~= nil
	end
end

function UnitIsVisible(unit)
	local u = units.ResolveUnit(unit)
	if u and u.visible then
		return 1
	end
end

function UnitIsPossessed(unit)
	local u = units.ResolveUnit(unit)
	if u and u.possessed then
		return 1
	end
end

function UnitPlayerOrPetInParty(unit)
	for i = 1, 4 do
		if UnitIsUnit(unit, "party"..i) or UnitIsUnit(unit, "partypet"..i) then
			return 1
		end
	end
end

function UnitPlayerOrPetInRaid(unit)
	for i = 1, 40 do
		if UnitIsUnit(unit, "raid"..i) or UnitIsUnit(unit, "raidpet"..i) then
			return 1
		end
	end
end

function UnitBuff(unit, index, filter)
	if filter then
		print("UnitBuff filter not supported")
	end
	local u = units.ResolveUnit(unit)
	if not u then return end
	local i = units.GetBuffIndex(u, index, "HELPFUL")
	if not i then return end
	local aura = u.auras[i]
	local applications = aura.applications
	applications = applications >= 0 and applications or nil
	return aura.name, aura.rank or "", aura.texture, applications
end

function UnitDebuff(unit, index, filter)
	if filter then
		print("UnitDebuff filter not supported")
	end
	local u = units.ResolveUnit(unit)
	if not u then return end
	local i = units.GetBuffIndex(u, index, "HARMFUL")
	if not i then return end
	local aura = u.auras[i]
	local applications = aura.applications
	applications = applications >= 0 and applications or nil
	return aura.name, aura.rank or "", aura.texture, applications
end

function UnitAura(unit, index, filter)
end

function UnitCharacterPoints(unit)
	return 0
end

function UnitPowerType(unit)
	return 0
end

function UnitHasRelicSlot(unit)
end

function UnitAffectingCombat(unit)
	return
end

function UnitInBattleground()
end

function UnitPlayerControlled()
end

function UnitClassification()
	local u = units.ResolveUnit(unit)
	return u and u.classification or "normal"
end

function UnitIsTapped()
end

function UnitReaction()
end

function UnitInRaid(unit)
end

function UnitSelectionColor(unit)
	return 1, 1, 1
end
